home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / DEMONSTR / ATEASY_2.ZIP / CDLL.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-02  |  7KB  |  182 lines

  1. {****************************************************************************
  2.  
  3.     PROGRAM: CDLL.pas
  4.     
  5.     BY     : Ronnie Yazma, Copyright 1993 GEOTEST Inc.   
  6.  
  7.     PURPOSE: Demonstarte None ATEasy type DLL functions.
  8.     
  9.     TO COMPILE:
  10.              Use Turbo pascal for window v1.5 or above.
  11.  
  12.     VERSION: 2.00 (Jul-26-93)
  13.  
  14.     FUNCTIONS/SUBROUTINES:
  15.  
  16.          - MaxSub() : finds the max between 2 floats
  17.          - MaxLongFunc() : return the max between 2 floats
  18.          - AverageArray() : find the avarage of float array
  19.          - NoSpaces() : delete leading & trailing spaces in a string
  20.          - UCase2Dim() : convert 2 dim string to upper case
  21.          
  22.     COMMENTS:
  23.            When using None ATEasy type DLL the parameters are passed from ATEasy
  24.            in the following way:
  25.            
  26.            ATEasy                   DLL                     Remarks
  27.            --------------------------------------------------------------------------
  28.            VAL Byte                 shortint                byte and char also applicable
  29.            VAR Byte                 var x:shortint or ^shortint
  30.            VAL Int                  integer                 word also applicable
  31.            VAR Int                  var x:integer or ^integer
  32.            VAL Long                 longint
  33.            VAR Long                 var x:longint or longint
  34.            VAL Float                double                  $N+ must be inside
  35.            VAR Float                var x:double or ^double
  36.            VAL/VAR String[]         pchar or var x:array[1..32767] of char
  37.                                                             null terminated string
  38.                                                             when using pchar and the strings unit -
  39.                                                             $X+ must be inside                                            
  40.            VAL/VAR String[,]        var x:ppchar            array of pointers to strings
  41.                                                             declare type ppchar = array[1..32767] of pchar
  42.            VAL/VAR xxx [] or [,]    var x:array[range] of xxx
  43.                                                             xxx is Byte/Int/Long/Float
  44.                                                             range is normally 1..32767 but can be any other
  45.                                                             2 dim range also applicable if known
  46.  
  47. ****************************************************************************}
  48.  
  49. {$N+}                       { Must be on for ATEasy Types }
  50. {$M 1024, 1024}
  51. {$X+}
  52.  
  53. library CDLL;
  54. uses wintypes,              { Must be included for windows types }
  55.      strings;               { Must be included when using strings from ateasy }
  56.  
  57. type
  58.     doublearray = array [1..8091] of double; { for AverageArray }
  59.     ppchar = array [1..16383] of pchar;      { for UCase2Dim }
  60.  
  61. {****************************************************************************
  62.  
  63.     FUNCTION: MaxSub(dX1, dX2, dResult)
  64.  
  65.     PURPOSE:  Finds the max of 2 floats (dX1 & dX2) into lpdResult.
  66.  
  67.        This subroutine defined in ATEasy as:
  68.        Max(fX1: VAL FLOAT, fX2: VAL FLOAT, fResult: VAR FLOAT): SUB DLL
  69.  
  70. ****************************************************************************}
  71. procedure MaxSub(dX1, dX2 : double; var dResult : double); export;
  72. begin
  73.     if dX1 < dX2 then
  74.         dResult:=dX2
  75.     else
  76.         dResult:=dX1;
  77. end;
  78.  
  79. {****************************************************************************
  80.  
  81.     FUNCTION: MaxLongFunc(lX1, lX2)
  82.  
  83.     PURPOSE:  Returns the max of 2 longs (lX1 & lX2).
  84.               Note that this is a function. 
  85.  
  86.        This function defined in ATEasy as:
  87.        Long Max(lX1: VAL LONG, lX2: VAL LONG): Function DLL
  88.  
  89. ****************************************************************************}
  90. function MaxLongFunc(lX1, lX2 : longint):longint; export; 
  91. begin   
  92.     if lX1 < lX2 then
  93.         MaxLongFunc:=lX2
  94.     else
  95.         MaxLongFunc:=lX1;
  96. end;
  97.  
  98. {****************************************************************************
  99.  
  100.     FUNCTION: AverageArray(adNumbers, iCount, dResult)
  101.  
  102.     PURPOSE:  Calculate the mean value of adNumbers array into dResult.
  103.  
  104.         This function defined in ATEasy as:
  105.         AverageArray(afNumbers : VAL FLOAT[], dResult : VAR FLOAT) : SUB DLL
  106.  
  107. ****************************************************************************}
  108. procedure AverageArray(var adNumbers : doublearray; iCount : integer; var dResult : double); export;
  109. var
  110.     i : integer;
  111. begin
  112.     dResult:=0.0;
  113.     for i:=1 to iCount do
  114.     dResult:=dResult+adNumbers[i];
  115.     if iCount <> 0 then
  116.     dResult:=dResult / iCount;
  117. end;
  118.  
  119. {****************************************************************************
  120.  
  121.     FUNCTION: NoSpaces(pcString)
  122.  
  123.     PURPOSE:  Delete leading & trailing spaces in a string
  124.  
  125.         This function defined in ATEasy as:
  126.         NoSpaces(s : VAR String)
  127.  
  128. ****************************************************************************}
  129. procedure NoSpaces(pcString : pchar); export;
  130. var
  131.     i, j : integer;
  132. begin
  133.     i:=StrLen(pcString);
  134.     while (i > 0) and (pcString[i-1] = ' ') do
  135.     dec(i);
  136.     pcString[i]:=#0;               { delete trailing spaces }
  137.     j:=0;
  138.     while (j <= i) and (pcString[j] = ' ') do
  139.         inc(j);
  140.     if (j > 0) then                { move to start }
  141.     move(pcString[j], pcString[0], i+1-j);
  142. end;
  143.  
  144. {****************************************************************************
  145.  
  146.     FUNCTION: UCase2Dim(ppcStrings)
  147.  
  148.     PURPOSE:  convert 2 dim string to upper case
  149.  
  150.         This function defined in ATEasy as:
  151.         UCase2Dim(as : VAR String[,])
  152.  
  153.     COMMENT : You can use the strings unit and the PChar type
  154.               when dealling with strings in a much more elegant way.    
  155.  
  156. ****************************************************************************}
  157. procedure UCase2Dim(var ppcStrings : ppchar; iCount : integer); export;
  158. var
  159.     i : integer;
  160. begin
  161.     for i:=1 to iCount do
  162.         StrUpper(ppcStrings[i]);
  163. end;
  164.  
  165. {****************************************************************************
  166.             Exports definition for the DLL
  167. ****************************************************************************}
  168.  
  169. exports  MaxSub            index 100;
  170. exports  MaxLongFunc       index 101;
  171. exports  AverageArray      index 102;
  172. exports  NoSpaces       index 103;
  173. exports  UCase2Dim       index 104;
  174.  
  175. begin
  176.     { Note:You can place here initialization code for your dll }
  177. end.
  178.  
  179. {****************************************************************************
  180.             E - O - F
  181. ****************************************************************************}
  182.